package uiLayer;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JTabbedPane;
import java.awt.GridBagConstraints;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextPane;

import modelLayer.Customer;
import modelLayer.Employee;
import modelLayer.ProductForLease;
import modelLayer.Sale;
import modelLayer.SaleLinesItem;

import controllerLayer.CustomerCtr;
import controllerLayer.EmployeeCtr;
import controllerLayer.LoanCtr;
import controllerLayer.ProductCtr;
import controllerLayer.SaleCtr;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class OfficeG extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTabbedPane tabbedPane;
	private JPanel panel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private JPanel panel_4;
	private JButton btnEnter;
	private JTextField txtCpr;
	private JTextField txtName;
	private JTextField txtPhoneNumber;
	private JTextField txtDiscount;
	private JLabel lblCprNumber;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblDiscount;
	private JButton btnCreate;
	private JLabel lblCreateCustomer;
	private JLabel lblFindCustomer;
	private JTextField txtCpr_1;
	private JLabel lblCprNumber_1;
	private JComboBox<String> comboBox;
	private JTextPane textPane;
	private JTextField txtAddress;
	private JTextField txtPhoneNumber_1;
	private JTextField txtDiscount_1;
	private JLabel lblAddress;
	private JLabel lblPhoneNumber;
	private JLabel lblDiscount_1;
	private ArrayList<Component> update;
	private CustomerCtr cctr;
	private static InputParser inp;
	private Customer customer;
	private Employee employee;
	private ArrayList<JTextField> tFields;
	private JTextField txtAddress_1;
	private JLabel lblAdress;
	private SaleCtr sctr;
	private ProductCtr pctr;
	private JLabel lblNewLabel_2;
	private JTextField txtCpr_2;
	private JLabel lblCprNumber_2;
	private JLabel lblName;
	private JLabel lblAddress_1;
	private JLabel lblSalary;
	private JLabel lblPhoneNumber_1;
	private JTextField txtName_1;
	private JTextField txtAddress_2;
	private JTextField txtSalary;
	private JTextField txtPhoneNumber_2;
	private JButton btnCreate_1;
	private JLabel lblFindEmployee;
	private JLabel lblCprNumber_3;
	private JTextField txtCpr_3;
	private JTextField txtAddress_3;
	private JLabel lblAddress_2;
	private JLabel lblSalary_1;
	private JTextField txtSalary_1;
	private JLabel lblPhoneNumber_2;
	private JTextField txtPhoneNumber_3;
	private JButton btnUpdate;
	private JTextPane textPane_1;
	private JComboBox<String> comboBox_1;
	private EmployeeCtr ectr;
	private ArrayList<Component> update_2;
	private JLabel lblNewProduct;
	private JLabel lblNewProduct_1;
	private JLabel lblName_1;
	private JLabel lblDescription;
	private JLabel lblPrice;
	private JLabel lblQuantity;
	private JLabel lblNewLabel_3;
	private JTextField txtName_2;
	private JTextField txtDescription;
	private JTextField txtPrice;
	private JTextField txtQuantity;
	private JTextField txtCategory;
	private JLabel lblFindProduct;
	private JLabel lblId;
	private JTextField txtId;
	private JLabel lblPrice_1;
	private JTextField txtPrice_1;
	private JLabel lblQuantity_1;
	private JTextField txtQua;
	private JButton btnCreate_2;
	private JButton btnUpdate_1;
	private JTextPane textPane_2;
	private JComboBox<String> comboBox_2;
	private ArrayList<Component> update_3;
	private LoanCtr lctr;
	private ProductForLease lpr;
	private JLabel lblName_2;
	private JLabel lblDescription_1;
	private JLabel lblPrice_2;
	private JLabel lblQuantity_2;
	private JLabel lblUnit;
	private JLabel lblLocation;
	private JLabel lblCategory;
	private JTextField txtName_3;
	private JTextField txtDescription_1;
	private JTextField txtPrice_2;
	private JTextField txtQuantity_1;
	private JTextField txtUnit;
	private JTextField txtLocation;
	private JTextField txtCategory_1;
	private JTextPane textPane_3;
	private JButton btnNewButton;
	private JLabel lblFindProduct_1;
	private JLabel lblQuan;
	private JLabel lblPrice_3;
	private JLabel lblLocation_1;
	private JLabel lblAlert;
	private JLabel lblContractorId;
	private JLabel lblAlert_1;
	private JLabel lblNewLabel_4;
	private JTextField txtAlert;
	private JTextField txtContractor;
	private JTextField txtQuantity_2;
	private JTextField txtPrice_3;
	private JTextField txtLocation_1;
	private JTextField txtAlert_1;
	private JTextField txtContractor_1;
	private JButton btnUpdate_2;
	private JComboBox<String> comboBox_3;
	private JLabel lblNewContractor;
	private JLabel lblId_1;
	private JLabel lblName_3;
	private JLabel lblAddress_3;
	private JLabel lblPhoneNumber_3;
	private JTextField txtId_1;
	private JTextField txtName_4;
	private JTextField txtAddress_4;
	private JTextField txtPhoneNumber_4;
	private JButton btnCreate_3;
	private JLabel lblFindContractor;
	private JLabel lblId_2;
	private JLabel lblAddress_4;
	private JLabel lblPhoneNumber_4;
	private JTextField txtId_2;
	private JTextField txtAddress_5;
	private JTextField txtPhoneNumber_5;
	private JButton btnUpdate_3;
	private JTextPane textPane_4;
	private ArrayList<Component>update_4;
	private ArrayList<Component>update_5;
	private JLabel lblId_3;
	private JTextField txtId_3;
	private JComboBox<String> comboBox_4;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {

					OfficeG frame = new OfficeG();
					inp.load();
					SaveToFile.getInstance().clearFile();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public OfficeG() {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				try {
					pctr.saveProd();
					ectr.save();
					cctr.save();
					pctr.saveContr();
					pctr.saveSLI();
					sctr.save();
					lctr.save();
				} 
				catch (IOException|NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(contentPane,"Saving error","Error",2);
				}			
			}
		});
		setTitle("Vestbjerg Byggecentrum A/S");
		 
		update_4 = new ArrayList<Component>();
		update_5 = new ArrayList<Component>();
		lctr = new LoanCtr();
		lpr = null;
		update_3 = new ArrayList<Component>();
		update_2 = new ArrayList<Component>();
		ectr = new EmployeeCtr();
		pctr = new ProductCtr();
		sctr = new SaleCtr();
		inp = InputParser.getInstance();
		cctr = new CustomerCtr();
		update = new ArrayList<Component>();
		tFields = new ArrayList<JTextField>();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 833, 569);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0};
		gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
		gbc_tabbedPane.fill = GridBagConstraints.BOTH;
		gbc_tabbedPane.gridx = 0;
		gbc_tabbedPane.gridy = 0;
		contentPane.add(tabbedPane, gbc_tabbedPane);
		
		panel = new JPanel();
		tabbedPane.addTab("Customer", null, panel, null);
		txtAddress_1 = new JTextField();
		txtAddress_1.setText("Address");
		txtAddress_1.setColumns(10);
		
		txtCpr = new JTextField();
		txtCpr.setText("CPR");
		txtCpr.setColumns(10);
		
		txtName = new JTextField();
		txtName.setText("Name");
		txtName.setColumns(10);
		
		txtPhoneNumber = new JTextField();
		txtPhoneNumber.setText("Phone Number");
		txtPhoneNumber.setColumns(10);
		
		txtDiscount = new JTextField();
		txtDiscount.setText("Discount");
		txtDiscount.setColumns(10);
		
		lblCprNumber = new JLabel("CPR Number:");
		
		lblNewLabel = new JLabel("Name:");
		
		lblNewLabel_1 = new JLabel("Phone Number:");
		
		lblDiscount = new JLabel("Discount:");
		
		btnCreate = new JButton("Create");
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				 String id = txtCpr.getText();
			        String name =txtName.getText();
			        String phoneNumber = txtPhoneNumber.getText();
			        String address = txtAddress_1.getText();
			        double  discount = InputParser.getInstance().parseDouble(txtDiscount.getText());
			        double moneySpent = 0;
					int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Create Customer",0,2);
			        if(re==0){cctr.createCustomer(id, name, address, phoneNumber, moneySpent, discount);
					textPane.setText(cctr.findCustomer(id)+ " has been created.");}
					
			        
			}
		});
		
		lblFindCustomer = new JLabel("Find Customer");
		
		txtCpr_1 = new JTextField();
		
		tFields.add(txtName);
		tFields.add(txtCpr_1);
		tFields.add(txtAddress_1);
		tFields.add(txtPhoneNumber);
		
		tFields.add(txtCpr);
		tFields.add(txtDiscount);
		
		
		txtCpr_1.setText("CPR");
		txtCpr_1.setColumns(10);
		
		lblCprNumber_1 = new JLabel("CPR Number:");
		
		comboBox = new JComboBox<String>();
		comboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			String id = txtCpr_1.getText(); 
				try{
					customer = cctr.getCustomer(id);
					customer.getAddress();
					txtCpr_1.setEnabled(false);
				if(comboBox.getSelectedItem()=="Update"){
					txtAddress.setText("Address");
					lblAddress.setText("Address:");
					for(final Component c: update){
						c.setVisible(true);
						if(c.getClass()==JTextField.class)c.addMouseListener(new MouseAdapter(){
							@Override
							public void mouseClicked(MouseEvent arg0) {
								((JTextField) c).setText("");
							}
						});
					}
					btnEnter.setText("Update"); 
					
				}
				else{ 
					for(Component c: update)c.setVisible(false);
					txtCpr_1.setEnabled(true);
					}
				if(comboBox.getSelectedItem()=="Delete"){
					btnEnter.setText("Delete"); 
					btnEnter.setVisible(true);
				}
				else txtCpr_1.setEnabled(true);
				if(comboBox.getSelectedItem()=="Print Offer"){
					try{
						sctr.printOffers(customer.getId());
					}
					catch(NullPointerException npe){
						textPane.setText("No offers created.");
				}
				}
				if(comboBox.getSelectedItem()=="Accept Offer"){
					lblAddress.setText("Offer's ID:");
					lblAddress.setVisible(true);
					txtAddress.setText("ID");
					txtAddress.setVisible(true);
					txtAddress.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent arg0) {
							txtAddress.setText("");
						}
					});
					btnEnter.setText("Accept");
					btnEnter.setVisible(true);
				}
			
				}
			catch(NullPointerException npe){
				textPane.setText("Customer doesn't exist");
				for(Component c: update)c.setVisible(false);
				comboBox.setSelectedIndex(0);
			}
				}});
		comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Update", "Delete", "Print Offers", "Accept Offer"}));
		
		txtAddress = new JTextField();
		txtAddress.setText("Address");
		txtAddress.setColumns(10);
		txtAddress.setVisible(false);
		update.add(txtAddress);
		
		txtPhoneNumber_1 = new JTextField();
		txtPhoneNumber_1.setText("Phone number");
		txtPhoneNumber_1.setColumns(10);
		txtPhoneNumber_1.setVisible(false);
		update.add(txtPhoneNumber_1);
		
		txtDiscount_1 = new JTextField();
		txtDiscount_1.setText("Discount");
		txtDiscount_1.setColumns(10);
		txtDiscount_1.setVisible(false);
		update.add(txtDiscount_1);
		
		lblAddress = new JLabel("Address:");
		lblAddress.setVisible(false);
		update.add(lblAddress);
		
		lblPhoneNumber = new JLabel("Phone Number:");
		lblPhoneNumber.setVisible(false);
		update.add(lblPhoneNumber);
		
		lblDiscount_1 = new JLabel("Discount:");
		lblDiscount_1.setVisible(false);
		update.add(lblDiscount_1);
		
		
		
		lblAdress = new JLabel("Address:");
		panel.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("31px"),
				ColumnSpec.decode("100px"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				ColumnSpec.decode("18px"),
				ColumnSpec.decode("65px"),
				ColumnSpec.decode("90px"),
				ColumnSpec.decode("84px"),
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("100px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("37px"),
				RowSpec.decode("14px"),
				FormFactory.PARAGRAPH_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.UNRELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.UNRELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.UNRELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.UNRELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.PARAGRAPH_GAP_ROWSPEC,
				RowSpec.decode("165px:grow"),}));
		
		lblCreateCustomer = new JLabel("Create Customer");
		panel.add(lblCreateCustomer, "2, 2, right, top");
		
		btnEnter = new JButton("Update");
		btnEnter.setVisible(false);
		update.add(btnEnter);
		btnEnter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(btnEnter.getText()=="Update"){customer.setAddress(txtAddress.getText());
				customer.setDiscount(inp.parseDouble(txtDiscount_1.getText()));
				customer.setPhoneNumber(txtPhoneNumber_1.getText());
				comboBox.setSelectedIndex(0);
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Customer",0,2);
				if(re==0)textPane.setText(cctr.findCustomer(customer.getId())+" has been updated.");
			}
			if(btnEnter.getText()=="Delete"){
				
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Delete Customer",0,2);
				if(re==0){textPane.setText(cctr.findCustomer(customer.getId())+ " has been deleted.");
				cctr.deleteCustomer(customer.getId());
				}
			}
			if(btnEnter.getText()=="Accept"){
				Sale sale = sctr.findSale(inp.parseInt(txtAddress.getText()));
				try{
				sale.printOffer(inp.parseInt(txtAddress.getText()));
				employee = sale.getEmployee();
				ArrayList<SaleLinesItem> sls = sale.getShoppingCart();
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Accept Offer",0,2);
				if(re==0)pctr.sellProduct(employee.getId(), customer.getId(), sls);
				}
				catch(NullPointerException npe){
					textPane.setText("Offer doesn't exist.");
				}
				
			}
			}
		});
		panel.add(btnEnter, "14, 4, left, top");
		panel.add(lblNewLabel_1, "2, 8, right, center");
		panel.add(txtPhoneNumber, "4, 8, left, top");
		panel.add(lblNewLabel, "2, 6, right, center");
		panel.add(txtName, "4, 6, left, top");
		panel.add(lblCprNumber, "2, 4, right, center");
		panel.add(txtCpr, "4, 4, left, top");
		panel.add(lblDiscount, "2, 12, right, center");
		panel.add(txtDiscount, "4, 12, left, center");
		panel.add(lblAdress, "2, 10, right, center");
		panel.add(txtAddress_1, "4, 10, left, top");
		panel.add(lblFindCustomer, "8, 2, right, top");
		panel.add(lblDiscount_1, "8, 10, right, center");
		panel.add(lblPhoneNumber, "8, 8, right, center");
		panel.add(lblAddress, "8, 6, right, center");
		panel.add(lblCprNumber_1, "8, 4, right, center");
		panel.add(txtAddress, "10, 6, left, top");
		panel.add(txtPhoneNumber_1, "10, 8, left, top");
		panel.add(txtDiscount_1, "10, 10, left, top");
		panel.add(txtCpr_1, "10, 4, left, top");
		panel.add(comboBox, "12, 4, fill, top");
		panel.add(btnCreate, "6, 12, 2, 1, left, top");
		
		textPane = new JTextPane();
		panel.add(textPane, "1, 14, 14, 1, fill, fill");
		
		
		
		panel_1 = new JPanel();
		tabbedPane.addTab("Employee", null, panel_1, null);
		
		lblNewLabel_2 = new JLabel("Create Employee");
		
		txtCpr_2 = new JTextField();
		txtCpr_2.setText("CPR");
		txtCpr_2.setColumns(10);
		tFields.add(txtCpr_2);
		
		lblCprNumber_2 = new JLabel("CPR Number:");
		
		lblName = new JLabel("Name:");
		
		lblAddress_1 = new JLabel("Address:");
		
		lblSalary = new JLabel("Salary:");
		
		lblPhoneNumber_1 = new JLabel("Phone number:");
		
		txtName_1 = new JTextField();
		txtName_1.setText("Name");
		txtName_1.setColumns(10);
		tFields.add(txtName_1);
		
		txtAddress_2 = new JTextField();
		txtAddress_2.setText("Address");
		txtAddress_2.setColumns(10);
		tFields.add(txtAddress_2);
		
		txtSalary = new JTextField();
		txtSalary.setText("Salary");
		txtSalary.setColumns(10);
		tFields.add(txtSalary);
		
		txtPhoneNumber_2 = new JTextField();
		txtPhoneNumber_2.setText("Phone Number");
		txtPhoneNumber_2.setColumns(10);
		tFields.add(txtPhoneNumber_2);
		
		lblFindEmployee = new JLabel("Find Employee");
		
		lblCprNumber_3 = new JLabel("CPR Number:");
		
		txtCpr_3 = new JTextField();
		txtCpr_3.setText("CPR");
		txtCpr_3.setColumns(10);
		tFields.add(txtCpr_3);
		
		txtAddress_3 = new JTextField();
		txtAddress_3.setText("Address");
		txtAddress_3.setColumns(10);
		txtAddress_3.setVisible(false);
		update_2.add(txtAddress_3);
		
		lblAddress_2 = new JLabel("Address:");
		lblAddress_2.setVisible(false);
		update_2.add(lblAddress_2);
		
		lblSalary_1 = new JLabel("Salary:");
		lblSalary_1.setVisible(false);
		update_2.add(lblSalary_1);
		
		txtSalary_1 = new JTextField();
		txtSalary_1.setText("Salary");
		txtSalary_1.setColumns(10);
		txtSalary_1.setVisible(false);
		update_2.add(txtSalary_1);
		
		lblPhoneNumber_2 = new JLabel("Phone Number:");
		lblPhoneNumber_2.setVisible(false);
		update_2.add(lblPhoneNumber_2);
		
		txtPhoneNumber_3 = new JTextField();
		txtPhoneNumber_3.setText("Phone Number");
		txtPhoneNumber_3.setColumns(10);
		txtPhoneNumber_3.setVisible(false);
		update_2.add(txtPhoneNumber_3);
		panel_1.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("31px"),
				ColumnSpec.decode("100px"),
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				ColumnSpec.decode("8px"),
				ColumnSpec.decode("78px"),
				ColumnSpec.decode("90px"),
				ColumnSpec.decode("84px"),
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				ColumnSpec.decode("18px"),
				ColumnSpec.decode("100px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("37px"),
				RowSpec.decode("14px"),
				FormFactory.PARAGRAPH_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				RowSpec.decode("20px"),
				RowSpec.decode("145px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		
		comboBox_1 = new JComboBox<String>();
		comboBox_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String id = txtCpr_3.getText(); 
				try{
					employee = ectr.getEmployee(id);
					employee.getAddress();
					txtCpr_3.setEnabled(false);
				if(comboBox_1.getSelectedItem()=="Update"){
					txtAddress_3.setText("Address");
					lblAddress_2.setText("Address:");
					for(final Component c: update_2){
						c.setVisible(true);
						if(c.getClass()==JTextField.class)c.addMouseListener(new MouseAdapter(){
							@Override
							public void mouseClicked(MouseEvent arg0) {
								((JTextField) c).setText("");
							}
						});
					}
					btnUpdate.setText("Update"); 
					
					
				}
				else{ 
					for(Component c: update_2)c.setVisible(false);
					txtCpr_3.setEnabled(true);
					}
				if(comboBox_1.getSelectedItem()=="Delete"){
					btnUpdate.setText("Delete"); 
					btnUpdate.setVisible(true);
				}
				else txtCpr_3.setEnabled(true);
				if(comboBox_1.getSelectedItem()=="Sort"){
					textPane_1.setText(ectr.sortEmployees());
				}
				
				}
			catch(NullPointerException npe){
				textPane_1.setText("Employee doesn't exist");
				for(Component c: update_2)c.setVisible(false);
				comboBox_1.setSelectedIndex(0);
			}
				}
			
		});
		comboBox_1.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Update", "Delete", "Sort"}));
		panel_1.add(comboBox_1, "12, 4, fill, top");
		
		btnUpdate = new JButton("Update");
		btnUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(btnUpdate.getText()=="Update"){
					String address =txtAddress_3.getText();
				double salary = inp.parseDouble(txtSalary_1.getText());
				String phoneNumber = txtPhoneNumber_3.getText();
				comboBox_1.setSelectedIndex(0);
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Employee",0,2);
				if(re==0){
					ectr.updateEmployee(address, phoneNumber, salary, employee.getId());
				textPane_1.setText(ectr.findEmployee(employee.getId())+" has been updated.");
				}
			}
			if(btnUpdate.getText()=="Delete"){
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Delete Employee",0,2);
				if(re==0){textPane_1.setText(ectr.findEmployee(employee.getId())+ " has been deleted.");
				ectr.deleteEmployee(employee.getId());	
			}
			}
			}
		});
		btnUpdate.setVisible(false);
		update_2.add(btnUpdate);
		panel_1.add(btnUpdate, "14, 4, left, top");
		panel_1.add(lblPhoneNumber_1, "2, 12, right, center");
		panel_1.add(lblSalary, "2, 10, right, center");
		panel_1.add(lblAddress_1, "2, 8, right, center");
		panel_1.add(lblName, "2, 6, right, center");
		panel_1.add(lblCprNumber_2, "2, 4, right, center");
		panel_1.add(txtAddress_2, "4, 8, left, top");
		panel_1.add(txtName_1, "4, 6, left, top");
		panel_1.add(txtSalary, "4, 10, left, top");
		panel_1.add(txtCpr_2, "4, 4, left, top");
		panel_1.add(lblAddress_2, "8, 6, right, center");
		panel_1.add(lblCprNumber_3, "8, 4, right, center");
		panel_1.add(lblSalary_1, "8, 8, right, center");
		panel_1.add(lblPhoneNumber_2, "8, 10, right, center");
		panel_1.add(txtAddress_3, "10, 6, left, top");
		panel_1.add(txtSalary_1, "10, 8, left, top");
		panel_1.add(txtPhoneNumber_3, "10, 10, left, center");
		panel_1.add(txtCpr_3, "10, 4, left, top");
		panel_1.add(txtPhoneNumber_2, "4, 12, left, center");
		panel_1.add(lblNewLabel_2, "2, 2, right, top");
		panel_1.add(lblFindEmployee, "8, 2, left, top");
		
		btnCreate_1 = new JButton("Create");
		btnCreate_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String id = txtCpr_2.getText();
				String name = txtName_1.getText();
				String address = txtAddress_2.getText();
				String phnr = txtPhoneNumber_2.getText();
				double salary = inp.parseDouble(txtSalary.getText());
				double moneyEarned = 0;
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Create Employee",0,2);
				if(re==0){ectr.createEmployee(id, name, address, phnr, salary, moneyEarned);
				textPane_1.setText(ectr.getEmployee(id).toString() + " has been created");
			}
			}
		});
		panel_1.add(btnCreate_1, "6, 12, left, top");
		
		textPane_1 = new JTextPane();
		panel_1.add(textPane_1, "1, 14, 14, 7, fill, fill");
		
		panel_2 = new JPanel();
		tabbedPane.addTab("Product For Sale", null, panel_2, null);
		panel_2.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("31px"),
				ColumnSpec.decode("85px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(93px;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.UNRELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(100px;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("31px"),
				RowSpec.decode("14px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		lblNewProduct = new JLabel("New Product");
		panel_2.add(lblNewProduct, "2, 2, right, top");
		
		lblFindProduct_1 = new JLabel("Find Product");
		panel_2.add(lblFindProduct_1, "10, 2, right, default");
		
		lblName_2 = new JLabel("Name:");
		panel_2.add(lblName_2, "2, 4, right, center");
		
		txtName_3 = new JTextField();
		txtName_3.setText("Name");
		panel_2.add(txtName_3, "4, 4, left, top");
		txtName_3.setColumns(10);
		tFields.add(txtName_3);
		
		lblId_3 = new JLabel("ID:");
		panel_2.add(lblId_3, "10, 4, right, default");
		
		txtId_3 = new JTextField();
		txtId_3.setText("ID");
		panel_2.add(txtId_3, "12, 4, fill, default");
		txtId_3.setColumns(10);
		tFields.add(txtId_3);
		
		btnUpdate_2 = new JButton("Update");
		btnUpdate_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(comboBox_3.getSelectedItem()=="Update"){
				String id = txtId_3.getText();
				String location = txtLocation_1.getText();
				double price = inp.parseDouble(txtPrice_3.getText());
				double quantity = inp.parseDouble(txtQuantity_2.getText());
				String contid = txtContractor.getText();
				int alert = inp.parseInt(txtAlert.getText());
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Product",0,2);
				try{
					if(re==0){pctr.updateItem(id, contid, quantity, location, price, alert);
				
				textPane_3.setText(pctr.findItem(inp.parseInt(id)) + " has been created");
					}
					}
				catch(NullPointerException npe){
				textPane_3.setText("Contractor doesn't exist");	
				
					}
				}
				if(comboBox_3.getSelectedItem()=="Delete"){
					String id = txtId_3.getText();
					int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Product",0,2);
					if(re==0){
					textPane_3.setText(pctr.findItem(inp.parseInt(id))+"has been deleted.");
					pctr.deleteItem(id);
					}
					
				}
				if(comboBox_3.getSelectedItem()=="Create Collection"){
					String name = txtId_3.getText();
					int re = JOptionPane.showConfirmDialog(btnUpdate_2, "             Are you sure?","Create Collection",0,2);
					if(re==0){
						
					String id = pctr.createCollection(name);
					textPane_3.setText(pctr.getSaleLinesItem(id).toString()+"has been created.");
					}
				}
				
				if(comboBox_3.getSelectedItem()=="Add To Collection"){
					int id = inp.parseInt(txtId_3.getText());
					String collectionID = txtQuantity_2.getText();
					int re = JOptionPane.showConfirmDialog(btnUpdate_2, "             Are you sure?","Add To Collection",0,2);
					if(re==0){
					try{	
					pctr.addToSLI(id, collectionID);
					textPane_3.setText(pctr.findItem(id)+"has been added to collection: " + pctr.getSaleLinesItem(collectionID).toString());
					}
					catch(NullPointerException npe){
						textPane_3.setText(npe.getMessage());
					}
					}
				}
			}
		});
		panel_2.add(btnUpdate_2, "16, 4, left, default");
		update_4.add(btnUpdate_2);
		
		
		
		lblDescription_1 = new JLabel("Description:");
		panel_2.add(lblDescription_1, "2, 6, right, center");
		
		txtDescription_1 = new JTextField();
		txtDescription_1.setText("Description");
		panel_2.add(txtDescription_1, "4, 6, left, top");
		txtDescription_1.setColumns(10);
		tFields.add(txtDescription_1);
		
		lblQuan = new JLabel("Quantity:");
		panel_2.add(lblQuan, "10, 6, right, default");
		update_4.add(lblQuan);
		
		txtQuantity_2 = new JTextField();
		txtQuantity_2.setText("Quantity");
		panel_2.add(txtQuantity_2, "12, 6, left, default");
		txtQuantity_2.setColumns(10);
		update_4.add(txtQuantity_2);
		
		lblPrice_2 = new JLabel("Price:");
		panel_2.add(lblPrice_2, "2, 8, right, center");
		
		txtPrice_2 = new JTextField();
		txtPrice_2.setText("Price");
		panel_2.add(txtPrice_2, "4, 8, left, top");
		txtPrice_2.setColumns(10);
		tFields.add(txtPrice_2);
		
		lblPrice_3 = new JLabel("Price:");
		panel_2.add(lblPrice_3, "10, 8, right, default");
		update_4.add(lblPrice_3);
		
		txtPrice_3 = new JTextField();
		txtPrice_3.setText("Price");
		panel_2.add(txtPrice_3, "12, 8, left, default");
		txtPrice_3.setColumns(10);
		update_4.add(txtPrice_3);
		
		lblQuantity_2 = new JLabel("Quantity:");
		panel_2.add(lblQuantity_2, "2, 10, right, center");
		
		txtQuantity_1 = new JTextField();
		txtQuantity_1.setText("Quantity");
		panel_2.add(txtQuantity_1, "4, 10, left, top");
		txtQuantity_1.setColumns(10);
		tFields.add(txtQuantity_1);
		
		lblLocation_1 = new JLabel("Location:");
		panel_2.add(lblLocation_1, "10, 10, right, default");
		update_4.add(lblLocation_1);
		
		txtLocation_1 = new JTextField();
		txtLocation_1.setText("Location");
		panel_2.add(txtLocation_1, "12, 10, left, default");
		txtLocation_1.setColumns(10);
		update_4.add(txtLocation_1);
		
		lblUnit = new JLabel("Unit:");
		panel_2.add(lblUnit, "2, 12, right, center");
		
		txtUnit = new JTextField();
		txtUnit.setText("Unit");
		panel_2.add(txtUnit, "4, 12, left, top");
		txtUnit.setColumns(10);
		tFields.add(txtUnit);
		
		lblAlert = new JLabel("Alert:");
		panel_2.add(lblAlert, "10, 12, right, default");
		update_4.add(lblAlert);
		
		txtAlert_1 = new JTextField();
		txtAlert_1.setText("Alert");
		panel_2.add(txtAlert_1, "12, 12, left, default");
		txtAlert_1.setColumns(10);
		update_4.add(txtAlert_1);
		
		lblLocation = new JLabel("Location:");
		panel_2.add(lblLocation, "2, 14, right, center");
		
		txtLocation = new JTextField();
		txtLocation.setText("Location");
		panel_2.add(txtLocation, "4, 14, left, top");
		txtLocation.setColumns(10);
		tFields.add(txtLocation);
		
		lblContractorId = new JLabel("Contractor ID:");
		panel_2.add(lblContractorId, "10, 14, right, default");
		update_4.add(lblContractorId);
		
		txtContractor_1 = new JTextField();
		txtContractor_1.setText("Contractor");
		panel_2.add(txtContractor_1, "12, 14, left, default");
		txtContractor_1.setColumns(10);
		update_4.add(txtContractor_1);
		
		lblCategory = new JLabel("Category:");
		panel_2.add(lblCategory, "2, 16, right, center");
		
		txtCategory_1 = new JTextField();
		txtCategory_1.setText("Category");
		panel_2.add(txtCategory_1, "4, 16, left, top");
		txtCategory_1.setColumns(10);
		tFields.add(txtCategory_1);
		
		lblAlert_1 = new JLabel("Alert:");
		panel_2.add(lblAlert_1, "2, 18, right, default");
		
		txtAlert = new JTextField();
		txtAlert.setText("Alert");
		panel_2.add(txtAlert, "4, 18, left, default");
		txtAlert.setColumns(10);
		tFields.add(txtAlert);
		
		lblNewLabel_4 = new JLabel("Contractor ID:");
		panel_2.add(lblNewLabel_4, "2, 20, right, default");
		
		txtContractor = new JTextField();
		txtContractor.setText("Contractor");
		panel_2.add(txtContractor, "4, 20, left, default");
		txtContractor.setColumns(10);
		tFields.add(txtContractor);
		
		btnNewButton = new JButton("Create");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String description = txtDescription_1.getText();
				String name = txtName_3.getText();
				String location = txtLocation.getText();
				String unit = txtUnit.getText();
				double price = inp.parseDouble(txtPrice_2.getText());
				double quantity = inp.parseDouble(txtQuantity_1.getText());
				String category = txtCategory.getText();
				String contid = txtContractor.getText();
				int alert = inp.parseInt(txtAlert.getText());
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Create Product",0,2);
				if(re==0){int id = pctr.createItem(contid, unit, name, description, price, quantity, category, location, alert);
				textPane_3.setText(pctr.findItem(id) + " has been created");
			}
			}
		});
		panel_2.add(btnNewButton, "6, 20");
		
		comboBox_3 = new JComboBox<String>();
		comboBox_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String id = txtId_3.getText(); 
				if(comboBox_3.getSelectedItem()=="Update"||comboBox_3.getSelectedItem()=="Delete"){
					try{
				
					pctr.findItem(inp.parseInt(id));
					txtId_3.setEnabled(false);
				if(comboBox_3.getSelectedItem()=="Update"){
					txtId_3.setText("ID");
					lblId_3.setText("ID:");
					for(final Component c: update_4){
						c.setVisible(true);
						if(c.getClass()==JTextField.class)c.addMouseListener(new MouseAdapter(){
							@Override
							public void mouseClicked(MouseEvent arg0) {
								((JTextField) c).setText("");
							}
						});
					}
					btnUpdate_2.setText("Update"); 
				
					
				}
				
				else{ 
					for(Component c: update_4)c.setVisible(false);
					txtId_3.setEnabled(true);
					}
				if(comboBox_3.getSelectedItem()=="Delete"){
					txtId_3.setText("ID");
					lblId_3.setText("ID:");
					btnUpdate_2.setText("Delete"); 
					btnUpdate_2.setVisible(true);
				}
				else txtId_3.setEnabled(true);
				}
				catch(NullPointerException npe){
					textPane_3.setText("Product doesn't exist");
					for(Component c: update_4)c.setVisible(false);
					comboBox_3.setSelectedIndex(0);
				}
				}
				else{
				if(comboBox_3.getSelectedItem()=="Create Collection"){
					for(Component c: update_4)c.setVisible(false);
					
					txtId_3.setText("Name");
				lblId_3.setText("Name:");
				btnUpdate_2.setText("Create");
				txtId_3.setVisible(true);
				lblId_3.setVisible(true);
				btnUpdate_2.setVisible(true);
				}
				if(comboBox_3.getSelectedItem()=="Add To Collection"){
					txtId_3.setText("ID Of Product");
					lblId_3.setText("ID Of Product:");
					btnUpdate_2.setText("Submit");
					btnUpdate_2.setVisible(true);
					txtQuantity_2.setText("Collection Name");
					lblQuan.setText("Collection Name:");
					txtQuantity_2.setVisible(true);
					lblQuan.setVisible(true);
				}
				}
			
			}
		});
		comboBox_3.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Update", "Delete", "Create Collection", "Add To Collection"}));
		panel_2.add(comboBox_3, "14, 4, fill, default");
		for(Component c:update_4) c.setVisible(false);
		
		textPane_3 = new JTextPane();
		panel_2.add(textPane_3, "1, 24, 16, 9, fill, fill");
		
		panel_3 = new JPanel();
		tabbedPane.addTab("Product For Lease", null, panel_3, null);
		panel_3.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("31px"),
				ColumnSpec.decode("100px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("65px"),
				ColumnSpec.decode("90px"),
				ColumnSpec.decode("60px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(100px;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("31px"),
				RowSpec.decode("14px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		lblNewProduct_1 = new JLabel("New Product");
		panel_3.add(lblNewProduct_1, "1, 2, 2, 1, right, top");
		
		lblFindProduct = new JLabel("Find Product");
		panel_3.add(lblFindProduct, "7, 2, 2, 1, right, top");
		
		lblName_1 = new JLabel("Name:");
		panel_3.add(lblName_1, "2, 4, right, center");
		
		txtName_2 = new JTextField();
		txtName_2.setText("Name");
		panel_3.add(txtName_2, "4, 4, left, top");
		txtName_2.setColumns(10);
		tFields.add(txtName_2);
		
		lblId = new JLabel("ID:");
		panel_3.add(lblId, "8, 4, right, center");
		
		txtId = new JTextField();
		txtId.setText("ID");
		panel_3.add(txtId, "10, 4, left, top");
		txtId.setColumns(10);
		tFields.add(txtId);
		
		comboBox_2 = new JComboBox<String>();
		comboBox_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int id = inp.parseInt(txtId.getText()); 
				try{
					lpr = lctr.getProduct(id);
					lpr.getDescription();
					txtId.setEnabled(false);
				if(comboBox_2.getSelectedItem()=="Update"){
					for(final Component c: update_3){
						c.setVisible(true);
						if(c.getClass()==JTextField.class)c.addMouseListener(new MouseAdapter(){
							@Override
							public void mouseClicked(MouseEvent arg0) {
								((JTextField) c).setText("");
							}
						});
					}
					btnUpdate.setText("Update"); 
					
					
				}
				else{ 
					for(Component c: update_3)c.setVisible(false);
					txtId.setEnabled(true);
					}
				if(comboBox_2.getSelectedItem()=="Delete"){
					btnUpdate_1.setText("Delete"); 
					btnUpdate_1.setVisible(true);
				}
				else txtId.setEnabled(true);
				if(comboBox_2.getSelectedItem()=="Return"){
					int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Return Product",0,2);
					if(re==0){textPane_2.setText(lpr.toString()+ "has been returned");
					lctr.returnProduct(id);
					
				}
					comboBox_2.setSelectedIndex(0);
				}
				
				}
			catch(NullPointerException npe){
				textPane_2.setText("Product doesn't exist");
				for(Component c: update_3)c.setVisible(false);
				comboBox_2.setSelectedIndex(0);
			}
			}
		});
		comboBox_2.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Update", "Delete", "Return"}));
		panel_3.add(comboBox_2, "12, 4, fill, default");
		
		btnUpdate_1 = new JButton("Update");
		btnUpdate_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int id = inp.parseInt(txtId.getText());
				if(btnUpdate_1.getText()=="Update"){
					
				double price = inp.parseDouble(txtPrice_1.getText());
				double quantity = inp.parseDouble(txtQua.getText());
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Product",0,2);
				if(re==0){lctr.updateLProduct(id, quantity, price);
				lpr = lctr.getProduct(id);
				textPane_2.setText(lpr.toString() + " has been updated");
				}
			}
			if(btnUpdate_1.getText()=="Delete"){
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Delete Product",0,2);
				if(re==0){textPane_2.setText(lctr.findLProduct(id) + " has been deleted.");
				lctr.deleteProduct(id);	
			}
			}
			}
		});
		panel_3.add(btnUpdate_1, "14, 4, left, default");
		update_3.add(btnUpdate_1);
		
		lblDescription = new JLabel("Description:");
		panel_3.add(lblDescription, "1, 6, 2, 1, right, center");
		
		txtDescription = new JTextField();
		txtDescription.setText("Description");
		panel_3.add(txtDescription, "4, 6, left, top");
		txtDescription.setColumns(10);
		tFields.add(txtDescription);
		
		lblPrice_1 = new JLabel("Price:");
		panel_3.add(lblPrice_1, "8, 6, right, center");
		update_3.add(lblPrice_1);
		
		txtPrice_1 = new JTextField();
		txtPrice_1.setText("Price");
		panel_3.add(txtPrice_1, "10, 6, left, top");
		txtPrice_1.setColumns(10);
		update_3.add(txtPrice_1);
		
		lblPrice = new JLabel("Price:");
		panel_3.add(lblPrice, "2, 8, right, center");
		
		txtPrice = new JTextField();
		txtPrice.setText("Price");
		panel_3.add(txtPrice, "4, 8, left, top");
		txtPrice.setColumns(10);
		tFields.add(txtPrice);
		
		lblQuantity_1 = new JLabel("Quantity:");
		panel_3.add(lblQuantity_1, "8, 8, right, center");
		update_3.add(lblQuantity_1);
		
		txtQua = new JTextField();
		txtQua.setText("Quantity");
		panel_3.add(txtQua, "10, 8, left, top");
		txtQua.setColumns(10);
		update_3.add(txtQua);
		
		lblQuantity = new JLabel("Quantity:");
		panel_3.add(lblQuantity, "2, 10, right, center");
		
		txtQuantity = new JTextField();
		txtQuantity.setText("Quantity");
		panel_3.add(txtQuantity, "4, 10, left, top");
		txtQuantity.setColumns(10);
		tFields.add(txtQuantity);
		
		lblNewLabel_3 = new JLabel("Category:");
		panel_3.add(lblNewLabel_3, "2, 12, right, center");
		
		txtCategory = new JTextField();
		txtCategory.setText("Category");
		panel_3.add(txtCategory, "4, 12, left, top");
		txtCategory.setColumns(10);
		tFields.add(txtCategory);
		
		btnCreate_2 = new JButton("Create");
		btnCreate_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String name = txtName_2.getText();
				String description = txtDescription.getText();
				double price = inp.parseDouble(txtPrice.getText());
				double quantity = inp.parseDouble(txtQuantity.getText());
				String category = txtCategory.getText();
				String state = "available";
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Create Product",0,2);
				if(re==0){
				int id = lctr.createLItem(name, description, price, quantity, category, state);
				lpr = lctr.getProduct(id);
				textPane_2.setText(lpr.toString() + " has been created");
			}
			}
		});
		panel_3.add(btnCreate_2, "6, 12, 2, 1, left, fill");
		
		textPane_2 = new JTextPane();
		panel_3.add(textPane_2, "1, 20, 14, 3, fill, fill");
		for(Component c:update_3)c.setVisible(false);
		panel_4 = new JPanel();
		tabbedPane.addTab("Contractor", null, panel_4, null);
		panel_4.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("max(31px;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("100px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("85px"),
				ColumnSpec.decode("102px"),
				ColumnSpec.decode("87px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("86px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("100px"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				RowSpec.decode("31px"),
				RowSpec.decode("14px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("20px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("23px"),
				RowSpec.decode("31px"),
				RowSpec.decode("309px"),}));
		
		lblNewContractor = new JLabel("New Contractor");
		panel_4.add(lblNewContractor, "3, 2, right, top");
		
		lblFindContractor = new JLabel("Find Contractor");
		panel_4.add(lblFindContractor, "9, 2, right, top");
		
		lblId_1 = new JLabel("ID:");
		panel_4.add(lblId_1, "3, 4, right, center");
		
		txtId_1 = new JTextField();
		txtId_1.setText("ID");
		panel_4.add(txtId_1, "5, 4, left, top");
		txtId_1.setColumns(10);
		tFields.add(txtId_1);
		
		lblId_2 = new JLabel("ID:");
		panel_4.add(lblId_2, "9, 4, right, center");
		
		txtId_2 = new JTextField();
		txtId_2.setText("ID");
		panel_4.add(txtId_2, "11, 4, left, top");
		txtId_2.setColumns(10);
		tFields.add(txtId_2);
		
		btnUpdate_3 = new JButton("Update");
		btnUpdate_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(btnUpdate_3.getText()=="Update"){
					String phnr = txtPhoneNumber_5.getText();
					String address = txtAddress_5.getText();
					String Id = txtId_3.getText();
					int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Update Contractor",0,2);
					if(re==0){pctr.updateContractor(Id, address, phnr);
					textPane_4.setText(pctr.getContractor(Id).toString()+"has been updated.");
			}
				}
			if(btnUpdate_3.getText()=="Delete"){
				String id = txtId_3.getText();
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Delete Contracotr",0,2);
				if(re==0){
				textPane_4.setText(pctr.findContractor(id)+ " has been deleted.");
				pctr.deleteContractor(id);	
			}
			}
			}
		});
		panel_4.add(btnUpdate_3, "15, 4, left, top");
		update_5.add(btnUpdate_3);
		
		
		
		lblName_3 = new JLabel("Name:");
		panel_4.add(lblName_3, "3, 6, right, center");
		
		txtName_4 = new JTextField();
		txtName_4.setText("Name");
		panel_4.add(txtName_4, "5, 6, left, top");
		txtName_4.setColumns(10);
		tFields.add(txtName_4);
		
		lblAddress_4 = new JLabel("Address:");
		panel_4.add(lblAddress_4, "9, 6, right, center");
		update_5.add(lblAddress_4);
		
		txtAddress_5 = new JTextField();
		txtAddress_5.setText("Address");
		panel_4.add(txtAddress_5, "11, 6, left, top");
		txtAddress_5.setColumns(10);
		update_5.add(txtAddress_5);
		
		lblAddress_3 = new JLabel("Address:");
		panel_4.add(lblAddress_3, "3, 8, right, center");
		
		txtAddress_4 = new JTextField();
		txtAddress_4.setText("Address");
		panel_4.add(txtAddress_4, "5, 8, left, top");
		txtAddress_4.setColumns(10);
		tFields.add(txtAddress_4);
		
		lblPhoneNumber_4 = new JLabel("Phone Number:");
		panel_4.add(lblPhoneNumber_4, "9, 8, right, center");
		update_5.add(lblPhoneNumber_4);
		
		txtPhoneNumber_5 = new JTextField();
		txtPhoneNumber_5.setText("Phone Number");
		panel_4.add(txtPhoneNumber_5, "11, 8, left, top");
		txtPhoneNumber_5.setColumns(10);
		update_5.add(txtPhoneNumber_5);
		
		lblPhoneNumber_3 = new JLabel("Phone Number:");
		panel_4.add(lblPhoneNumber_3, "3, 10, right, center");
		
		txtPhoneNumber_4 = new JTextField();
		txtPhoneNumber_4.setText("Phone Number");
		panel_4.add(txtPhoneNumber_4, "5, 10, left, center");
		txtPhoneNumber_4.setColumns(10);
		tFields.add(txtPhoneNumber_4);
		btnCreate_3 = new JButton("Create");
		btnCreate_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String phnr = txtPhoneNumber_4.getText();
				String address = txtAddress_4.getText();
				String Id = txtId_1.getText();
				String name = txtName_4.getText();
				int re = JOptionPane.showConfirmDialog(btnCreate,"             Are you sure?","Create Contractor",0,2);
				if(re==0){
				pctr.createContractor(Id, name, address, phnr);
				textPane_4.setText(pctr.getContractor(Id).toString()+"has been created.");
				}
				}
		});
		panel_4.add(btnCreate_3, "7, 10, left, top");
		
		textPane_4 = new JTextPane();
		panel_4.add(textPane_4, "1, 12, 15, 1, fill, fill");
		comboBox_4 = new JComboBox<String>();
		comboBox_4.setSelectedItem("");
		
		comboBox_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String id = txtId_2.getText(); 
				try{
					pctr.getContractor(id);
					txtId_2.setEnabled(false);
				if(comboBox_4.getSelectedItem()=="Update"){
					for(final Component c: update_5){
						c.setVisible(true);
						if(c.getClass()==JTextField.class)c.addMouseListener(new MouseAdapter(){
							@Override
							public void mouseClicked(MouseEvent arg0) {
								((JTextField) c).setText("");
							}
						});
					}
					btnUpdate_3.setText("Update"); 
					
					
				}
				
				else{ 
					for(Component c: update_5)c.setVisible(false);
					txtId.setEnabled(true);
					}
				if(comboBox_4.getSelectedItem()=="Delete"){
					btnUpdate_3.setText("Delete"); 
					btnUpdate_3.setVisible(true);
				}
				else txtId.setEnabled(true);
				
				}
			catch(NullPointerException npe){
				textPane_4.setText("Contractor doesn't exist");
				for(Component c: update_5)c.setVisible(false);
				comboBox_4.setSelectedIndex(0);
			}
			}
		});
		comboBox_4.setModel(new DefaultComboBoxModel<String>(new String[] {"", "Update", "Delete"}));
		if(comboBox_4.getSelectedItem()=="")for(final Component c:update_5)c.setVisible(false);
		panel_4.add(comboBox_4, "13, 4, fill, default");
		for(final JTextField tf: tFields){
			tf.addMouseListener(new MouseAdapter(){
				@Override
				public void mouseClicked(MouseEvent arg0) {
					tf.setText("");
				}
			});
			}
		for(final JTextField ft: tFields)
			ft.addKeyListener(new KeyAdapter() {
				int i = 0;
				@Override
				public void keyPressed(KeyEvent arg0) {
					if(i==0)ft.setText("");
					i++;
				}
			});
	}
}
